package com.juyu.miliao.api.controller;

import javax.annotation.Resource;

import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.juyu.miliao.api.domain.Blacklist;
import com.juyu.miliao.api.service.BlacklistService;
import com.juyu.miliao.api.validator.BlacklistCheck;
import com.juyu.miliao.common.domain.Subject;

@RestController
@RequestMapping("blacklist")
public class BlacklistController {
	@Resource
	BlacklistService blacklistService;
	/**
	 * 新增用户拉黑关系
	 * @param token
	 * @param entity
	 */
	@PostMapping
	public void blacklistRelation(Authentication token, @Validated(BlacklistCheck.class) Blacklist entity){
		Subject subject = (Subject) token.getPrincipal();
		entity.setUserId(subject.getId());
		blacklistService.blacklistRelation(entity);
	}
	
	/**
	 * 查询是否被拉黑(是否可以通话)
	 */
	@GetMapping("/{blacklistUserId}")
	public String findCountBlacklist(Authentication token, @PathVariable("blacklistUserId") long blacklistUserId) {
		Subject subject = (Subject) token.getPrincipal();
		return blacklistService.findCountBlacklist(subject.getId(),blacklistUserId);
	}
}
